<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>修改手机号 - {:config('web.WEB_TIT')}</title>
	{include file="member/public"}
</head>
<body>
	<header data-am-widget="header" class="am-header am-header-default jz">
		<div class="am-header-left am-header-nav">
			<a href="javascript:history.back()" class="">
				<i class="am-icon-chevron-left"></i>
			</a>
		</div>
		<h1 class="am-header-title">
			<a href="#title-link" class="">修改手机号</a>
		</h1>
	</header>
	<ul class="nav maa" style="margin-top: 10px;">
		<li>
			<span>原手机号码</span>
			<span style="margin-left: 1rem;">{$member.encryption_mobile}</span>
		</li>
		<li>
			<span>现手机号码</span>
			<input type="text" name="mobile" id="mobile" value="" placeholder="请输入要修改的手机号"/>
		</li>
		<li>
			<span>验证码</span>
			<input type="hidden" name="__token__" id="token" value="{$Request.token}" />
			<input type="" name="code" id="code" value="" placeholder="请输入验证码" style="width: 30%;"/>
			<em>获取验证码</em>
		</li>
	</ul>
	<div class="shure" id="submit">
		<a href="">绑定新手机</a>
	</div>
	<script type="text/javascript">
		$('#submit').click(function(){
			var mobile = $('#mobile').val();
			var code = $('#code').val();
			if(code == ''){
				alert('请输入验证码');
				return false;
			}

            var myreg = /^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-3]{1})|(15[5-9]{1})|(18[0-9]{1}))+\d{8})$/;
            if(mobile == ''){
                alert('手机号码不能为空');
                return false;
            }else if(mobile.length !=11){
                alert('请输入长度11位的手机号码');
                return false;
            }else if(!myreg.test(mobile)){
                alert('请输入有效的手机号码');
                return false;
            }

			$.ajax({
				type: 'POST',
				url : "{:url('member/set_mobile')}",
				data:{
                    mobile:mobile,
					code:code,
					token:$('#token').val()
				},
				dataType:'json',
				success: function(data){
                    if(data.code == 200){
                        alert(data.msg)
                        window.location.href = "{:url('member/set')}";
                    }else{
                        alert(data.msg)
                        location.reload(true);
                    }
				},
			});
		});
	</script>
</body>
</html>
